/**
 * Demonstrates a range of Button options the framework offers out of the box
 */
Ext.define('cloud.view.article.Article', {
    extend: 'Ext.navigation.View',
    xtype: 'article',
    requires: ['Ext.List', 'Ext.TitleBar', 'Ext.field.Select', 'Ext.field.Search'],
    config: {
        defaultBackButtonText: '返回',
        items: {
            xtype: 'container',
            layout: 'card',
            title: '资讯',
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'bottom',
                    layout: {
                        type: 'hbox',
                        pack: 'center'
                    },
                    items: [
                        {
                            xtype: 'button',
                            id: 'article_add',
                            iconMask: true,
                            cls: 'x-button2',
                            text: '添加'
                        }
                    ]
                },
                {
                    xtype: 'toolbar',
                    ui: 'dark',
                    docked: 'top',
                    items: [
                        {
                            xtype: 'textfield',
                            id: 'article_search',
                            name: 'article_search',
                            placeHolder: '请输入资讯名'
                        },
                        {xtype: 'spacer'},
                        {
                            xtype: 'selectfield',
                            store: 'ArticleCategoryStore',
                            id: 'article_ccid',
                            name: 'ccid',
                            displayField: 'name',
                            valueField: 'ccid',
                            listeners: {
                                change: function () {
                                    var ccid = Ext.getCmp('article_ccid').getValue();
                                    var store = Ext.getStore('ArticleColumnFindStore');
                                    store.load({params: {ccid: ccid}});
                                },
                                painted: function () {
                                    var store = Ext.getStore('ArticleCategoryStore');
                                    store.load({params: {cadid: localStorage.getItem('cadid')}});
                                    store .getProxy().setExtraParam('ccid', Ext.getCmp('article_ccid').getValue());
                                }
                            }
                        }
                    ]
                },
                {
                    xtype: 'list',
                    title: '资讯列表',
                    store: 'ArticleColumnFindStore',
                    pressedCls: false,
                    selectedCls: false,
                    cls: 'x-list2',
                    onItemDisclosure: true,
                    emptyText: '暂无资讯',
                    itemTpl: '<div class="listName">{name}</div>' +
                        '<div class="listConten">' +
                        '<span style="width: 50px;">是否开启：{statusvalue}</span>' +
                        '<span>时间： {[Ext.Date.format(new Date(parseInt(values.lasttime) * 1000), "Y-m-d H:i")]}</span>' +
                        '</div>'+
                        '<div class="listConten">' +
                        '<span>资讯简介： {summary}</span>' +
                        '</div>',
                    plugins: [
                        {
                            xclass: 'Ext.plugin.PullRefresh',
                            pullRefreshText: '下拉可以更新',
                            releaseRefreshText: '松开开始更新',
                            style: 'top:12px',
                            loadingText: '正在刷新……',
                            refreshFn: function (loaded, arguments) {
                               loaded.getList().getStore().getProxy().setExtraParam('ccid', Ext.getCmp('article_ccid').getValue()); //设置proxy参数
                                loaded.getList().getStore().loadPage(1, {
                                    callback: function (record, operation, success) {
                                        Ext.Viewport.unmask();
                                    }, scope: this });
                            }
                        },
                        {
                            xclass: 'Ext.plugin.ListPaging',
                            loadMoreText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">点击加载更多。。。。</h2>',
                            noMoreRecordsText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">没有更多条记录了</h2>',
                            autoPaging: false //设置为TRUE将自动触发
                        }
                    ],
                    listeners: {
                        initialize: function () {
                            var ccid = Ext.getCmp('article_ccid').getValue();
                            var store = Ext.getStore('ArticleColumnFindStore');
                            store.load({params: {ccid: ccid}});
                        }
                    }
                }
            ]
        }
    }
});